package com.sky.mapper;

import com.sky.AutoFIle.AutoFiles;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 修改菜品信息
     * @param dish
     */
    @AutoFiles(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据id来查询菜品信息
     * @param id
     * @return
     */
    @Select("select *from dish where id=#{id}")
    Dish  selectById(Long id);

    /**
     * 根据id来批量删除
     * @param ids
     */
    void deleteByid(List<Long> ids);

    /**
     * 新增菜品
     * @param dish
     */
    void Insert(Dish dish);

    /**
     * 根据id来查找信息并封装进视图
     * @param id
     * @return
     */
        @Select("select dish.*,category.name categoryName from dish left outer join category on dish.category_id=category.id where dish.id=#{id}")
        DishVO selectByIdVO(Long id);

    /**
     * 根据分类id来查询
     * @param categoryId
     * @return
     */
    @Select("select *from dish where category_id=#{categoryId}")
    List<Dish> listDish(Integer categoryId);

    /**
     * 分页查询
     * @param queryDTO
     * @return
     */
    List<DishVO> pagelist(DishPageQueryDTO queryDTO);

    /**
     * 根据分类来查询菜  一定是起售
     * @param categoryId
     * @return
     */
    @Select("select d.*,c.name categoryName from dish d left join category c on d.category_id=c.id  where d.status=1 and d.category_id=#{categoryId}")
    List<DishVO> SelectBycategoryId(Long categoryId);
}
